package com.youyicloud.api;

import com.alibaba.fastjson.JSONObject;
import com.youyicloud.constants.Constants;
import com.youyicloud.service.OssService;
import com.youyicloud.vo.ResponseBodyEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class OssApi {

    @Autowired
    private OssService ossService;

    @RequestMapping("ossSign")
    public ResponseBodyEntity ossSign(String dir) throws Exception{
        ResponseBodyEntity responseBodyEntity = new ResponseBodyEntity();
        responseBodyEntity.setData(ossService.sign(dir));
        return responseBodyEntity;
    }

    @RequestMapping("ossCallBack")
    public ResponseBodyEntity ossCallBack(String bucket,String filename,String object,String etag,String size,String mimeType,String my_var) throws Exception{
        ResponseBodyEntity responseBodyEntity = new ResponseBodyEntity();
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("bucket",bucket);
        jsonObject.put("filename",filename);
        jsonObject.put("object",object);
        jsonObject.put("etag",etag);
        jsonObject.put("size",size);
        jsonObject.put("mimeType",mimeType);
        jsonObject.put("my_var",my_var);
        responseBodyEntity.setData(jsonObject);
        responseBodyEntity.setState(Constants.SUCCEED);
        responseBodyEntity.setMsg("oss上传回调信息");
        return responseBodyEntity;
    }


}
